package com.wuchao.FlowBean;

import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

/**
 * 作者：吴超
 * 邮箱：wuchao_19931120@163.com
 * 时间：2021-10-28
 * 描述：
 */

public class FlowReducer extends Reducer<Text, FlowBean, Text, FlowBean> {

    private FlowBean outV = new FlowBean();

    @Override
    protected void reduce(Text key, Iterable<FlowBean> values, Context context) throws IOException, InterruptedException {

        long totalUp = 0;
        long totalDown = 0;

        for (FlowBean flowbean : values) {
            totalUp += flowbean.getUpFlow();
            totalDown += flowbean.getDownFlow();
        }

        outV.setUpFlow(totalUp);
        outV.setDownFlow(totalDown);
        outV.setSumFlow();

        context.write(key, outV);

    }
}
